{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d0eab1cd",
   "metadata": {},
   "outputs": [],
   "source": [
    "#向文件输出内容（向文件输出一段话）\n",
    "#方法一\n",
    "fp=open('D:/test.txt','w')   #第一个‘’内指向文件路径 第二个‘w’指write，也可以用a+\n",
    "print('努力遇见更好的自己'，fp=file)\n",
    "fp.close()\n",
    "#方法二   使用文件读写操作\n",
    "with open('D:/test.txt','w') as file:\n",
    "    file.write('努力遇见更好的自己')\n",
    "    "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
